<div class="portlet box grey">
    <div class="portlet-title">
        <div class="caption">
            <a class="btn green float-left" href="<?php echo url_for('@poll_add') ?>"><span class="icon-plus"> Нэмэх</span></a>
        </div>
        <div class="tools">
            <a href="javascript:;" class="collapse"></a>
        </div>
        <form method="get" class="form-horizontal">
            <div class="control-group float-left">                
                <input name="name" value="<?php echo $name ?>"/>
            </div>
            <div class="control-group float-left">
                <button type="submit" class="btn btn-primary">
                    <i class="icon-filter icon-white"></i> Шүүх
                </button>
            </div>
        </form>
    </div>
    <div class="portlet-body">
        <div class="widget-box">
            <table class="table table-bordered table-hover">
                <thead>
                    <tr>
                        <th></th>
                        <th>Асуулт</th>
                        <th>Үүсгэсэн огноо</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if ($rows): ?>
                        <?php foreach ($rows AS $row): ?>
                            <tr>
                                <td class="center" width="220">
                                    <?php echo link_to('<i class="icon-pencil tip-bottom"> Засах</i>', url_for('@poll_edit?id=' . $row['id']), array('class' => 'btn mini green')) ?>
                                    <?php if ($row['is_active'] == PollQuestionTable::ACTIVE): ?>
                                        <?php echo link_to('<i class="icon-trash tip-bottom"> Устгах</i>', '@poll_delete?id=' . $row['id'], array('confirm' => 'Та устгахдаа итгэлтэй байна уу?', 'class' => 'btn mini red')) ?>
                                    <?php endif; ?>
                                    <a class="btn mini blue" href="javascript:;" onclick="viewDetails(<?php echo $row['id'] ?>)"><i class="icon-info tip-bottom"> Дүн харах</i></a>
                                </td>
                                <td><?php echo $row['body'] ?></td>
                                <td><?php echo $row['created_at'] ?></td>
                            </tr>
                        <?php endforeach; ?>
                    <?php else: ?>
                        <tr>
                            <td colspan="11">Санал асуулга олдсонгүй</td>
                        </tr>
                    <?php endif; ?>
                </tbody>
                <tfoot>
                    <tr>
                        <th colspan="11">Нийт <?php echo count($rows) ?> санал асуулга байна</th>
                    </tr>
                </tfoot>
            </table>
        </div>
    </div>
</div>

<div id="ajax-modal" class="modal hide fade" tabindex="-1"></div>


<script>
    $.fn.modalmanager.defaults.resize = true;
    $.fn.modalmanager.defaults.spinner = '<div class="loading-spinner fade" style="width: 200px; margin-left: -100px;"><img src="/assets/img/ajax-modal-loading.gif" align="middle">&nbsp;<span style="font-weight:300; color: #eee; font-size: 18px; font-family:Open Sans;">&nbsp;Loading...</span></div>';

    var modal = $('#ajax-modal');

    function viewDetails(id) {
        $('body').modalmanager('loading');
        modal.load('<?php echo url_for('@poll_details') ?>/' + id, '', function() {
            modal.modal().on("hidden", function() {
                modal.empty();
            });
        });
    }

</script>